/*
 * Copyright © 2017 eqxiu.com 北京中网易企秀科技有限公司  All rights reserved.
 */

package cn.hermit.data.swagger;

import cn.hermit.data.json.factory.OrderedJSONFactory;
import cn.hermit.data.json.model.JSONArray;
import cn.hermit.data.json.model.JSONFactory;
import cn.hermit.data.json.model.JSONObject;

import java.util.LinkedHashMap;

/**
 * @author JackGao 高建国
 * @description //TODO 设计说明
 * @date 2/6/2017
 */
public class SwaggerContext extends LinkedHashMap<String, Object> {

    private static final long serialVersionUID = -3862770206144949436L;

    private JSONFactory jsonFactory;

    private JSONObject swagger;

    public SwaggerContext() {
        jsonFactory = new OrderedJSONFactory();
        swagger = jsonFactory.createObject();
        initSwagger();
    }

    public JSONObject getSwagger() {
        return swagger;
    }

    public JSONFactory getJsonFactory() {
        return jsonFactory;
    }

    private void initSwagger() {

        jsonFactory.objectEntry(swagger, "swagger", "2.0");

        JSONObject info = jsonFactory.createObject();
        jsonFactory.objectEntry(swagger, "info", info);
        jsonFactory.objectEntry(info, "version", "1.0.0");
        jsonFactory.objectEntry(info, "title", "Swagger Sample");
        jsonFactory.objectEntry(info, "description", "Swagger Sample");
        jsonFactory.objectEntry(info, "termsOfService", "http://eqxiu.com/terms/");
        JSONObject contact = jsonFactory.createObject();
        jsonFactory.objectEntry(info, "contact", contact);
        jsonFactory.objectEntry(contact, "email", "admin@eqxiu.com");
        JSONObject license = jsonFactory.createObject();
        jsonFactory.objectEntry(info, "license", license);
        jsonFactory.objectEntry(license, "name", "EQXIU");
        jsonFactory.objectEntry(license, "url", "http://eqxiu.com/licenses/LICENSE-2.0.html");


        jsonFactory.objectEntry(swagger, "host", "");
        jsonFactory.objectEntry(swagger, "basePath", "");

        JSONArray tags = jsonFactory.createArray();
        jsonFactory.objectEntry(swagger, "tags", tags);

        JSONArray schemes = jsonFactory.createArray();
        jsonFactory.objectEntry(swagger, "schemes", schemes);
        jsonFactory.arrayValue(schemes, "http");

        JSONObject paths = jsonFactory.createObject();
        jsonFactory.objectEntry(swagger, "paths", paths);

        JSONObject definitions = jsonFactory.createObject();
        jsonFactory.objectEntry(swagger, "definitions", definitions);
    }
}
